﻿create PROCEDURE Sync.SP_LoanFeasabilityStudyAttachments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanFeasabilityStudyAttachmentID],
		g.[LoanFeasabilityStudyID],g.[Attachment],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanFeasabilityStudyAttachments] g RIGHT JOIN Sync.LoanFeasabilityStudyAttachments_Tracking t  
    ON t.LoanFeasabilityStudyAttachmentID = g.LoanFeasabilityStudyAttachmentID 
    join [LoanFeasabilityStudy] fstudy
		on g.LoanFeasabilityStudyID = fstudy.LoanFeasabilityStudyID
		join [CustomerLoans] cl
		on fstudy.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END














